<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
<%@ include file="/pages/inc/taglibs.jsp" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<title>代码审查专家服务申请</title>
	<link rel="stylesheet" type="text/css" href="<c:url value='/styles/extends/ptsservice.css'/>" />
	<%@ include file="/pages/inc/header.jsp" %>
	<style>
	#ptsprofessor{color:blue}
	</style>
</head>
<body>
<%@ include file="/pages/inc/common.jsp" %>
<%@ include file="/pages/inc/menu.jsp" %>

<div class="pts-main">
	<%@ include file="/pages/inc/nav_pm.jsp" %>
	<div class="pts-page-title"><span>专家服务申请</span></div>
	<div class="container-fluid">
		<div id="codePackages"  class="servicefrom">
			<div class="row"> 
				<div class="cell">
				PTS专家服务申请： 创建中
				</div>
				<!-- <form id="commitService" name="commitService">
				  <input id="codePackagesID" name="codePackagesID" type="hidden" value="" />
				  <input id="projectId" name="projectId" type="hidden" value="" />
				  <input id="projectName" name="projectName" type="hidden" value="" />
				  <input id="serviceID" name="serviceID" type="hidden" value="" />
				  <input id="serviceName" name="serviceName" type="hidden" value="" />
				  <input id="status" name="status" type="hidden" value="0" />
				</form> -->
				<div class="cell">
					<button id="submit_button" class="button" type="button" onclick="buyservice();">提交</button>
					<button id="return_button" class="button" type="button" onclick="returnHome();">取消</button>
				</div>
			</div>
		</div>
		<div class="rowMsg">
			代码质量分析服务需要上传代码包。目前本项目已经上传有如下代码包，你可以选择已上传的代码包，也可以上传一个新的代码包。
		</div>
		<div class="ui-table ui-margin">
				   <button id="deleteBtn" class="button" type="button" onclick="batchDelete();"><fmt:message key='button.delete'/></button>
		
			<table id="codePackagesTable"></table>
			<div id="codePackagesPager"></div>
			<div class="nav">
				<form id="codePackagesForm" enctype="multipart/form-data">
					<input id="projectId" name="projectId" type="hidden" value="<%=projectId %>">
					<input id="serviceID" name="serviceID" type="hidden" value="" />
					<input id="codePackagesID" name="codePackagesID" type="hidden" value="" />
					<input id="projectName" name="projectName" type="hidden" value="" />
					<input id="serviceName" name="serviceName" type="hidden" value="" />
					<input id="status" name="status" type="hidden" value="0" />
					<div class="row" > 
						<div class="cell">
							<fmt:message key="codePackages.form.packagename"/>：
							<input id="packageFile" name="packageFile" type="file" />
							<span id="noFile" class="no_file_msg">* 请选择代码包</span>
						</div>
						<div class="cell">
							<fmt:message key="codePackages.form.packageversion"/>：
							<input id="packageversion" name="packageversion" type="text" class="text" style="width:40px;"/>
						</div>
						<div class="cell">
							<fmt:message key="codePackages.form.language"/>：
							<input id="language" name="language" type="text" class="text" style="width:40px;"/>
						</div>
						<div class="cell">
							<fmt:message key="codePackages.form.sources"/>：
							<input id="sources" name="sources" type="text" class="text" style="width:140px;"/>
						</div>
						<div class="cell">
							<button id="submit_button" class="button" type="button" onclick="save(this);">上传</button>&nbsp;&nbsp;
						</div>
					</div>
				</form>
			</div>
			<div class="cell" >
				申请专家服务，会同时创建任务信息和订单信息，用于服务任务跟踪和服务结算。
			</div>
		</div>
	</div>
</div>

<!-- 引入尾文件-->
<%@ include file="/pages/inc/footer.jsp" %>
<script type="text/javascript">
	var codePackagesGrid;
	var serviceID=null;
	
    $(function(){

    	serviceID=getUrlParam("serviceID");
		$("#serviceID").val(serviceID);
        if(serviceID==1){
           $("#serviceName").val("Java代码检查专家服务");
        }
        else{
           $("#serviceName").val(".Net代码检查专家服务");
        }
	   	 
    	codePackagesGrid = new biz.grid({
    		id : "#codePackagesTable",
    		url : "../codePackages/listCodePackages",
    		page : "<biz:out value='${page.pageNo}' default='1'/>",
    		rowNum : "<biz:out value='${page.pageSize}' default='15'/>",
			width : "auto",
			autoencode:false/*此项必须为false，不对单元格内容编码*/,
			singleselect:true/*单选框可用*/ ,
    		pager : "#codePackagesPager",
    		prmNames : {page:"pageNo",rows:"pageSize",sort:"orderFields",order:"order"},
    		sortname : "",
    		sortorder : "",
    		colModel : [
			    {name : "id",hidden:true,key:true},
			    {name : "projectId",hidden:true}, 
				{name : "packagename",label:"<fmt:message key="codePackages.queryResult.packagename"/>",width:200},
				{name : "extendName",label:"扩展名",width:35},
				{name : "packageversion",label:"<fmt:message key="codePackages.queryResult.packageversion"/>",width:40},
				{name : "updatetime",label:"<fmt:message key="codePackages.queryResult.updatetime"/>"},
				{name : "creator",label:"上传人"}
    		],
    		serializeGridData:function(postData){//添加查询条件值
    			var obj = biz.utils.serializeObject("#codePackagesForm");//示例中心搜索"biz.utils方法详解"查看方法说明
    			$.extend(true,obj,postData);//合并查询条件值与grid的默认传递参数
    			return obj;
    		},
    		onCellSelect:function(rowid, iCol, cellcontent, e){
    	      	//alert("id为" +rowid +"的第" + iCol + "列的单元格值为" + cellcontent);
    	      	$("#codePackagesID").val(rowid);
    	     }
    	});
    })

	function query(){
		codePackagesGrid.setGridParam({"page":"1"});
		codePackagesGrid.trigger('reloadGrid');
	}
	function add(){
		window.location="codePackages/add";
	}
	
	function edit(rowid){
		rowid = codePackagesGrid.getGridParam("selarrrow");
		if(rowid == null || rowid.length == 0){
			showInfo("<fmt:message key='grid.edit.chooseColAlert'/>",3000);
			return ;
		}else if(rowid.length > 1){
			showInfo("<fmt:message key='grid.edit.onlyOne'/>",3000);
			return ;
		}
		var id = codePackagesGrid.getCell(rowid[0],"id");
		window.location="codePackages/edit/" + id;
	}

	function view(){
		var rowid = codePackagesGrid.getGridParam("selarrrow");
		if(rowid == null || rowid.length == 0){
			showInfo("<fmt:message key='grid.view.chooseColAlert'/>",3000);
			return ;
		}else if(rowid.length > 1){
			showInfo("<fmt:message key='grid.view.onlyOne'/>",3000);
			return ;
		}
		var id = codePackagesGrid.getCell(rowid[0],"id");
		window.location="codePackages/show?id=" + id;
	}
	function batchDelete(rowid){
		var rowid = codePackagesGrid.getGridParam('selarrrow');
		if(rowid == null || rowid.length == 0){
			showInfo("<fmt:message key='grid.delete.chooseColAlert'/>",3000);
			return ;
		}
		new biz.alert({type:"confirm",message:I18N.msg_del_confirm,
			title:I18N.promp,callback:function(result){
	    		if (!result) {
	    			return;
	    		}
				var ids="";
				for(var i=0; i < rowid.length;i++){
					var id = codePackagesGrid.getCell(rowid[i],'id');
					if(i>0){
						ids +=',';
					}
					ids += id;
				}
				window.location="codePackages/delete/" + ids;
			}
		});
	}
	
	function save(button) {
		var projectId = null;
		var packageFile = null;

		projectId = $("#projectId").val();
		packageFile = $("#packageFile").val();
		
		form = button.form;
		if (!biz.validate("valid", form)) {
			showWarn("<fmt:message key='validation.object'/>", 3000);
			return;
		}
		if (projectId == "" || projectId == null) {
			return;
		}

		//不选择代码包禁止提交
		if (packageFile == "" || packageFile == null) {
			$("#noFile").css("display", "inline");
			return;
		}
		//form.submit();
		savePackage();
	}

	  function savePackage(){
		  new biz.ajaxsubmit({
	   	        id:"#codePackagesForm",
	   	        method:"POST",
	   	        url:"<c:url value='/codePackages/save'/>",
	   	        dataType:"json",
	   	        success:function(data, textStatus, jqXHR){
	   	        	codePackagesGrid.setGridParam({"page":"1"});
					codePackagesGrid.trigger('reloadGrid');
					$("#codePackagesID").val("");
	   	        },
				error:function(){
					showWarn("上传失败!", 3000);
				 }
	   	    }); 
	  }

	//确定购买服务 
	function  buyservice(){
		if($("#codePackagesID").val()==""){
			showWarn("请选择要提交的申请...", 3000);
			return;
		}
		new biz.ajaxsubmit({
        	id:"#codePackagesForm",
       		method:"POST",
       		dataType:"json",
        	url: "<c:url value='/serviceOrders/save'/>",
        	success: function(data, textStatus, jqXHR){
				showInfo("提交申请成功...",3000);
			},
			error:biz.utils.loadError
   		});
	}

	function  returnHome(){
		 window.location.href= contextPath+"/serviceOrders"; 
	}

    //获取jsp页面url参数的值，相当于request.getParameter('')一样。
	function  getUrlParam(name){ 
	      var   reg   =   new   RegExp("(^|&)"+   name   +"=([^&]*)(&|$)"); 
	      var   r   =   window.location.search.substr(1).match(reg); 
	      if   (r!=null)   return   unescape(r[2]);   return   null; 
	} 
	  
	new biz.file({
		id : "#packageFile",
		accept:"jar|zip"
	});
	</script>
</body>
</html>